import 'dayjs/locale/zh-cn';
import dayjs from 'dayjs';
import { setup } from 'jjb-dva-runtime-new';

dayjs.locale('zh-cn');

const app = setup();

if (!window.__POWERED_BY_QIANKUN__) {
  window.__coreLib = {};
  window.__coreLib.React = require('react');
  window.__coreLib.ReactDOM = require('react-dom');
  window.__coreLib.jjbCommonLib = require('jjb-common-lib-types');
}

/**
 * @description 挂载
 * @param props {{ setGlobalState: ({ rendered: boolean }) => void }}
 * @returns {Promise<*>}
 */
export const mount = async props => {
  window.__coreLib.React = require('react');
  window.__coreLib.ReactDOM = require('react-dom');
  window.__coreLib.jjbCommonLib = require('jjb-common-lib-types');
  props.setGlobalState({ rendered: true });
  app.mount();
};

/**
 * @description 卸载
 * @param props {object}
 * @returns {Promise<*>}
 */
export const unmount = async props => {
  app.unmount(props);
  delete window.__coreLib.React;
  delete window.__coreLib.ReactDOM;
  delete window.__coreLib.jjbCommonLib;
};

/**
 * @description 启动
 * @param props
 * @returns {Promise<*>}
 */
export const bootstrap = async props => app.bootstrap(props);
